package com.cwj;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Chenwujie
 * @date: 2021-06-02 14:19
 */
public class TestJson {
    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        Data data = new Data();
        data.setId(1);
        data.setRoleNames(new ArrayList<>());

        String s = objectMapper.writeValueAsString(data);
        System.out.println(s);

        Data data1 = objectMapper.readValue("{\"id\":1}", Data.class);
        System.out.println(data1);
    }
    private static class Data{
        private Integer id;
        private List<String> roleNames;

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public List<String> getRoleNames() {
            return roleNames;
        }

        public void setRoleNames(List<String> roleNames) {
            this.roleNames = roleNames;
        }
    }
}
